package com.sanpu.kxe.business.main.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.sanpu.kxe.R;
import com.sanpu.kxe.business.main.bean.PushDetailsBean;
import com.sanpu.kxe.jump.imageloader.JKImageLoader;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;

/**
 * Description：地推物料详情
 * Created by 薛勇军 on 2018/8/23.
 */

public class PushDetailAdapter extends BaseAdapter {

    private Context mContext;

    private List<PushDetailsBean> datas = new ArrayList<>();

    public PushDetailAdapter(Context mContext, List<PushDetailsBean> datas) {
        this.mContext = mContext;
        this.datas = datas;
    }

    public void setNotifyData(List<PushDetailsBean> datas) {
        this.datas = datas;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (datas == null)
            return 0;
        return datas.size();
    }

    @Override
    public PushDetailsBean getItem(int position) {
        if (datas == null)
            return null;
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_event_banner, null);
        }
        ImageView pushIv = ButterKnife.findById(convertView, R.id.event_item_image);
        PushDetailsBean detailBean = getItem(position);
        if (detailBean != null) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) pushIv.getLayoutParams();
            lp.width = (int)detailBean.getWidth();
            lp.height = (int)detailBean.getHeight();
            pushIv.setLayoutParams(lp);
            JKImageLoader.getInstance().displayImage(mContext, detailBean.getUrl(), pushIv);
        }
        return convertView;
    }
}
